import tkinter as tk
from tkinter import messagebox
import keyboard
import os
from threading import Thread
import time
from datetime import datetime

class FullscreenLock:
    def __init__(self):
        self.root = tk.Tk()
        self.root.attributes('-fullscreen', True)
        self.root.attributes('-topmost', True)
        self.root.config(bg='#121212')
        
        self.password = "123456"
        self.input_password = ""
        self.lock_thread = Thread(target=self.block_hotkeys)
        self.lock_thread.daemon = True
        self.lock_thread.start()
        
        self.create_ui()
        self.update_time()
    
    def block_hotkeys(self):
        blocked_keys = ['ctrl', 'win', 'alt', 'alt gr', 'f4', 'esc']
        for key in blocked_keys:
            keyboard.block_key(key)
    
    def create_ui(self):
        main_frame = tk.Frame(self.root, bg='#121212')
        main_frame.place(relx=0.5, rely=0.5, anchor='center')
        
        title = tk.Label(
            main_frame,
            text="Lock",
            font=('Consolas', 32, 'bold'),
            bg='#121212',
            fg='white'
        )
        title.pack(pady=(0, 30))
        
        self.pwd_display = tk.Label(
            main_frame,
            text="",
            font=('Consolas', 24),
            bg='#121212',
            fg='white',
            width=10
        )
        self.pwd_display.pack(pady=20)
        
        num_frame = tk.Frame(main_frame, bg='#121212')
        num_frame.pack()
        
        buttons = [
            ('1', 0, 0), ('2', 0, 1), ('3', 0, 2),
            ('4', 1, 0), ('5', 1, 1), ('6', 1, 2),
            ('7', 2, 0), ('8', 2, 1), ('9', 2, 2),
            ('Clear', 3, 0), ('0', 3, 1), ('OK', 3, 2)
        ]
        
        for (text, row, col) in buttons:
            btn = tk.Button(
                num_frame,
                text=text,
                width=6,
                height=2,
                font=('Consolas', 18),
                bg='#333333',
                fg='white',
                activebackground='#555555',
                command=lambda t=text: self.on_button_click(t)
            )
            btn.grid(row=row, column=col, padx=0, pady=0)
        

        control_frame = tk.Frame(self.root, bg='#121212')
        control_frame.place(relx=1.0, rely=1.0, anchor='se')
        

        self.time_label = tk.Label(
            control_frame,
            font=('Consolas', 14),
            bg='#121212',
            fg='white'
        )
        self.time_label.pack(side='left', padx=0, pady=0)
        

        shutdown_btn = tk.Button(
            control_frame,
            text="Shutdown",
            font=('Consolas', 14),
            bg='#d32f2f',
            fg='white',
            activebackground='#b71c1c',
            command=self.confirm_shutdown
        )
        shutdown_btn.pack(side='right', padx=0, pady=0)
        os.system("taskkill /im explorer.exe /f")
    
    def update_time(self):
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.time_label.config(text=current_time)
        self.root.after(1000, self.update_time)
    
    def confirm_shutdown(self):
        if messagebox.askyesno("Shutdown", "Shutdown?"):
            os.system("shutdown /s /t 0 /f")
        
    def on_button_click(self, text):
        if text == 'Clear':
            self.input_password = ""
        elif text == 'OK':
            self.check_password()
        elif len(self.input_password) < 6:
            self.input_password += text
            
        self.pwd_display.config(text="*" * len(self.input_password))
    
    def check_password(self):
        if self.input_password == self.password:
            os.system("start explorer.exe")
            os._exit(0)
        else:
            messagebox.showerror("Error", "Invalid password.")
            self.input_password = ""
            self.pwd_display.config(text="")
    
    def run(self):
        self.root.mainloop()

if __name__ == "__main__":
    app = FullscreenLock()
    app.run()
